package com.shanghaionstar.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.annotation.ContentView;
import com.onstar.cn.framework.mvp.base.core.BaseActivity;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;
import com.onstar.cn.mag.dealer.PreferredDealerEntity;
import com.shanghaionstar.swipe.SwipeActivity;
import com.shanghaionstar.utils.FinalConstants;

/**
 * Created by 7828wc on 2016/6/29.
 */
@ContentView(com.onstar.cn.framework.R.layout.fragment_container)
public class DiscoverActivity extends SwipeActivity {
    private FragmentManager fragmentManager;
    private String plateNumber;
    private String engineNumber;
    private PreferredDealerEntity preEntity;
    private String ssid;
    private String wifiPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fragmentManager = getSupportFragmentManager();

        String fragmentFlag = getIntent().getStringExtra(FinalConstants.JUMP_FLAG);
        changeFragment(fragmentFlag);

    }

    public void changeFragment(String fragmentFlag) {
        try {
            Class<?> clazz = Class.forName(fragmentFlag);
            if (clazz.newInstance() instanceof Fragment) {
                Fragment fragment = (Fragment) clazz.newInstance();
                if (!CommonUtil.isNull(getIntent().getExtras())) {
                    fragment.setArguments(getIntent().getExtras());
                }
                changeFragment(fragment, clazz, false);
            } else {
                Intent intent = new Intent(getApplicationContext(), clazz);
                startActivity(intent);
                finish();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public BasePresenter getPresenter() {
        return null;
    }

    @Override
    public void onBackPressed() {
        if (fragmentManager.getBackStackEntryCount() == 1) {
            this.finish();
        } else {
            super.onBackPressed();
        }
    }

    public String getPlateNumber() {
        return plateNumber;
    }

    public void setPlateNumber(String plateNumber) {
        this.plateNumber = plateNumber;
    }

    public String getEngineNumber() {
        return engineNumber;
    }

    public void setEngineNumber(String engineNumber) {
        this.engineNumber = engineNumber;
    }

    public PreferredDealerEntity getPreEntity() {
        return preEntity;
    }

    public void setPreEntity(PreferredDealerEntity preEntity) {
        this.preEntity = preEntity;
    }

    public String getWifiPassword() {
        return wifiPassword;
    }

    public void setWifiPassword(String wifiPassword) {
        this.wifiPassword = wifiPassword;
    }

    public String getSsid() {
        return ssid;
    }

    public void setSsid(String ssid) {
        this.ssid = ssid;
    }

}
